home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.031 < prev    next >
Encoding:
Text File  |  1989-01-04  |  3.2 KB  |  107 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple IIGS
  8. #31:    Redirecting Output in APW C
  9.  
  10. Revised by:    Guillermo Ortiz                                  November 1988
  11. Written by:    Guillermo Ortiz                                  November 1987
  12.  
  13. This Technical Note presents a sample program which shows how to send output 
  14. to different devices under the Apple Programmer's Workshop (APW) shell.
  15. _____________________________________________________________________________
  16.  
  17. Many programmers find the ability to redirect output an expecially useful 
  18. feature.  The following is a sample C program which allows this redirection 
  19. through an APW shell command.  Note that this is not applicable to MPW IIGS C 
  20. since it is not part of the APW environment.
  21.  
  22.     /*
  23.     redirect.c
  24.     Testing the shell REDIRECT command within APW C
  25.     Demonstrates how to send the output to different devices,
  26.     a disk file, the printer, and then back to the screen
  27.     last modified by Guillermo Ortiz 09/21/87
  28.  
  29.     NOTE: This program checks no errors whatsoever. It expects to
  30.     be able to open the file with no problems and expects the
  31.     printer to be readily available. 
  32.  
  33.     Also remember that for this test to work the file has to be of
  34.     the type 'EXE' (executable from the shell only.)
  35.     */
  36.  
  37.     #include <types.h>
  38.     #include <misctool.h>
  39.     #include <stdio.h>
  40.     #include <shell.h>
  41.     #include <string.h>
  42.  
  43.     char timestrg[20];           /* string to store the ascii time */
  44.     char myfile[80];             /* string to store the filename */
  45.     char str[80];                /* dummy string */
  46.     int dev=0x0001;              /* standard output */
  47.     int app=0x0000;              /* app=0 file is deleted, other will append */
  48.  
  49.     PrintToFile()
  50.     {
  51.      printf("Please enter the output filename: \n");
  52.      gets(myfile);
  53.      if (strlen(myfile)==0) 
  54.        {
  55.       printf("Error in entering the filename, quit.\n");
  56.       exit(0);
  57.     }
  58.  
  59.      /* REDIRECT call requires pascal string */
  60.      c2pstr(myfile);
  61.  
  62.     /* use the REDIRECT shell command to redirect the output to the file */
  63.      REDIRECT(dev, app, myfile);
  64.  
  65.      /* now print a few lines of text */
  66.      printf("This is my first line of text.\n");
  67.      printf("And this is the second line.\n");
  68.      printf("Finally the third and last line of text.\n");
  69.  
  70.     }
  71.  
  72.     PrintToPrinter()
  73.     {
  74.      /* now redirect to output to the .PRINTER. */
  75.      REDIRECT(dev, app, "\010.PRINTER.");
  76.  
  77.      printf("We should now be going to the printer.\n");
  78.      ReadAsciiTime(timestrg);
  79.      printf ("The time now is %s\n",timestrg);
  80.     }
  81.  
  82.     BackToScreen()
  83.     {  
  84.      /* Last REDIRECT the output back to the screen. */
  85.      REDIRECT(dev, app, "\010.CONSOLE.");
  86.  
  87.      printf("The testing of REDIRECTing the output is done.\n");
  88.      ReadAsciiTime(timestrg);
  89.      printf ("The time now is %s\n",timestrg);
  90.     }
  91.  
  92.     main()
  93.     {
  94.      ReadAsciiTime(timestrg);
  95.      printf ("The starting time is %s\n",timestrg);
  96.  
  97.      PrintToFile();
  98.      PrintToPrinter();
  99.      BackToScreen();
  100.     }
  101.  
  102.  
  103. Further Reference
  104. o    Apple IIGS Programmer's Workshop Reference
  105. o    Apple IIGS Programmer's Workshop C Reference
  106.  
  107.